package linkwechat.service.MenuService;

import linkwechat.mapper.LinkMenuMapper.LinkMenuMapper;
import linkwechat.pojo.LinkMenu;
import linkwechat.pojo.ReturnData;
import linkwechat.pojo.ReturnEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@Service
public class LinkMenuService {

    @Autowired
    LinkMenuMapper linkMenuMapper;

    public ReturnData getFristMenu(){
        List<LinkMenu> fristMenu = linkMenuMapper.getFristMenu();
        Collections.sort(fristMenu, new Comparator<LinkMenu>() {
            @Override
            public int compare(LinkMenu o1, LinkMenu o2) {
                return o1.getOrderNum()- o2.getOrderNum();
            }
        });
        return ReturnData.builder()
                .code(ReturnEnum.QUERY_SUCCEED.getCode())
                .msg(ReturnEnum.QUERY_SUCCEED.getMsg())
                .data(fristMenu)
                .build();
    }

    public ReturnData getZuoCheMenu(Long menuId) {
        return ReturnData.builder()
                .code(ReturnEnum.QUERY_SUCCEED.getCode())
                .msg(ReturnEnum.QUERY_SUCCEED.getMsg())
                .data(linkMenuMapper.getZuoCheMenu(menuId))
                .build();
    }
}
